package com.sina.rd.dsp.master;

import com.google.common.collect.Maps;
import com.sina.rd.dsp.protobuf.generated.RouteProtos;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

import java.util.HashMap;
import java.util.Properties;

import static com.sina.rd.dsp.protobuf.generated.ServerProtos.OperateCode;

/**
 * Created with IntelliJ IDEA.
 * User: xinrong3
 * Date: 14-4-3
 * Time: 上午11:31
 */
public class MasterServerHandler extends SimpleChannelInboundHandler<RouteProtos.ReqMessage> {
    public static final Log LOG = LogFactory.getLog(MasterServerHandler.class);

    private final Properties prop;
    private final HashMap<String,JedisPool> poolMap= Maps.newHashMap();
    private JedisPool jedisPool;

    public MasterServerHandler(Properties properties){
        super();
        this.prop=properties;
    }

    @Override
    protected void channelRead0(ChannelHandlerContext ctx, RouteProtos.ReqMessage msg) throws Exception {

    }

    @Override
    public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
        ctx.flush();
    }

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
        LOG.error(
                "Unexpected exception from downstream.", cause);
        ctx.close();
    }
}
